import { Observable, from } from 'rxjs'
import { map } from 'rxjs/operators'

import { WebSocketGateway, SubscribeMessage, WsResponse, WebSocketServer } from '@nestjs/websockets'
@WebSocketGateway()
export class RealtimeGateway {
  @WebSocketServer()
  server
  @SubscribeMessage('events')
  onEvent(client, data): Observable<WsResponse<number>> {
    const event = 'events'
    const response = [1, 2, 3]
    return from(response).pipe(map(res => ({ event, data: res })))
  }
}
